﻿using System.Globalization;
using System;
using System.Windows.Data;

namespace Xcj.Mes.WholeLine.ZH.HG.Shell.Converter
{
    public class OutFeedResultConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (((values?.Length ?? 0) < 8) 
                || (values[0] == null) || (values[1] == null)
                || (values[2] == null) || (values[3] == null)
                || (values[4] == null) || (values[5] == null)
                || (values[6] == null) || (values[7] == null))
                return string.Empty;

            try
            {
                int NotAgedResult      = int.Parse(values[0].ToString() ?? "0");
                int LC1Result          = int.Parse(values[1].ToString() ?? "0");
                int LC2Result          = int.Parse(values[2].ToString() ?? "0");
                int CapacityResult     = int.Parse(values[3].ToString() ?? "0");
                int LossResult         = int.Parse(values[4].ToString() ?? "0");
                int EsrResult          = int.Parse(values[5].ToString() ?? "0");
                int ConvexBottomResult = int.Parse(values[6].ToString() ?? "0");
                int ImplosionResult    = int.Parse(values[7].ToString() ?? "0");

                /*
                 * 开短路状态数据 00 无料 20 良品 11 开短路不良 12 重测 13 超上限(短路) 14 超下限(开路) 15 未触发或过流
                 * 未老化状态数据 00 无料 20 良品 11 未老化不良 12 重测 13 超上限 14 超下限 15 未触发或过流
                 * LC1状态数据    00 无料 20 良品 11 漏电不良   12 重测 13 超上限 14 超下限
                 * LC2状态数据    00 无料 20 良品 11 漏电不良   12 重测 13 超上限 14 超下限
                 * CX状态数据     00 无料 20 良品 11 损耗不良   12 重测 13 超上限 14 超下限 
                 * Esr状态数据    00 无料 20 良品 11 Esr不良    12 重测 13 超上限 14 超下限 
                 */

                if ((NotAgedResult == 20)
                    && (LC1Result == 20)
                    && (LC2Result == 20)
                    && (CapacityResult == 20)
                    && (LossResult == 20)
                    && (EsrResult == 20)
                    && ((ConvexBottomResult == 20) || (ConvexBottomResult == 0))
                    && ((ImplosionResult == 20) || (ImplosionResult == 0)))
                    return "良品";
                else
                {
                    if (NotAgedResult == 11)
                        return "未老化不良";
                    else if (NotAgedResult == 12)
                        return "未老化重测";
                    else if (NotAgedResult == 13)
                        return "未老化超上限";
                    else if (NotAgedResult == 14)
                        return "未老化超下限"; 
                    else if ((ConvexBottomResult != 20) && (ConvexBottomResult != 0))
                        return "凸底不良";
                    else if ((ImplosionResult != 20) && (ImplosionResult != 0))
                        return "内爆不良";
                    else if (LC1Result == 11)
                        return "漏电一不良";
                    else if (LC1Result == 12)
                        return "漏电一重测";
                    else if (LC1Result == 13)
                        return "漏电一超上限";
                    else if (LC1Result == 14)
                        return "漏电一超下限";
                    else if (LC2Result == 11)
                        return "漏电二不良";
                    else if (LC2Result == 12)
                        return "漏电二重测";
                    else if (LC2Result == 13)
                        return "漏电二超上限";
                    else if (LC2Result == 14)
                        return "漏电二超下限";
                    else if ((LossResult == 11) || (LossResult == 13) || (LossResult == 14))
                        return "损耗不良";
                    else if (LossResult == 12)
                        return "损耗重测";
                    else if (CapacityResult == 11)
                        return "容量不良";
                    else if (CapacityResult == 12)
                        return "容量重测";
                    else if (CapacityResult == 13)
                        return "高容";
                    else if (CapacityResult == 14)
                        return "低容";
                    else if (EsrResult == 11)
                        return "Esr不良";
                    else if (EsrResult == 12)
                        return "Esr重测";
                    else if (EsrResult == 13)
                        return "Esr超上限";
                    else if (EsrResult == 14)
                        return "Esr超下限";
                    else
                        return "良品";
                }
            }
            catch { }

            return "重测";
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}

